<template>
	<view class="Recharge">
		<view class="RechargeBox">
			<view class="Rechargemode">
				<view class="Rechargetitle">充值方式</view>
				<view class="RechargeList">
					<view class="RechargeItem" v-for="(item,index) in Recharge" @click="selectItem(index)">
						<view class="item_L">
							<view class="RechargeImage">
								<image :src="item.image" mode=""></image>
							</view>
							<view class="RechargeName">{{item.name}}</view>
						</view>
						<view class="item_R" :class="{currentColor:current==index}">
							<view v-if="current==index">
								<u-icon name="checkmark" color="#FFAC3F" size="25"></u-icon>
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="amountBox">
				<view class="amountTitle">充值金额</view>
				<view class="inputBox">
					￥<input type="number" placeholder="请输入充值金额" v-model="amount" @blur="checkMoney" />
				</view>
			</view>
			<view class="RechargeBtn" @click="recharge">充值</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {wxPayment,zfbPayment} from "@/utils/app.js";
	export default {
		data() {
			return {
				Recharge:[],
				current:0,
				amount:0
			}
		},
		onLoad() {
      // #ifdef APP-PLUS
      var args = plus.runtime.arguments;
      if(args){
        app.$vm.setShareDetail(args);
      }
      // #endif
			// #ifdef MP-WEIXIN
			this.Recharge = [{name:"微信支付",image:"/static/mine/WeChat.png"}];
			// #endif
			// #ifdef APP
			this.Recharge = [{name:"支付宝支付",image:"/static/mine/Alipay.png"},{name:"微信支付",image:"/static/mine/WeChat.png"}];
			// #endif
		},
		methods: {
			checkMoney(e){
				console.log(e)
				let money = Number(e.detail.value);
				if(money<0.01){
					this.amount = 1;
					this.$refs.uToast.show({
						title:"充值金额最少一元",
						type:"error",
						duration:2000
					})
				}
			},
			selectItem(index){
				this.current = index
			},
			recharge(){
				let obj = {};
				obj.money = this.amount;
				if(!this.amount.trim()||this.amount<0.01){
					this.$refs.uToast.show({
						title:"充值金额最少一元",
						type:"error",
						duration:2000
					})
					return false;
				}
				// #ifdef MP-WEIXIN
				obj.pay_type = 10;
				// #endif
				// #ifdef APP
				if(this.current==0){
					obj.pay_type = 30;
				}else if(this.current==1){
					obj.pay_type = 20;
				}
				// #endif
				console.log(obj)
				this.$u.api.userRecharge(obj).then(res=>{
					console.log(res)
					if(obj.pay_type==10||obj.pay_type==20){
						wxPayment(JSON.parse(res.data.data.sign)).then(rep=>{
							this.$refs.uToast.show({
								title:"支付成功",
								type:"success",
								duration:2000
							})
							setTimeout(()=>{
								uni.navigateBack({
									delta:1
								})
							},1500)
						});
					}else if(obj.pay_type==30){
						zfbPayment(res.data.data).then(rep=>{
							this.$refs.uToast.show({
								title:"支付成功",
								type:"success",
								duration:2000
							})
							setTimeout(()=>{
								uni.navigateBack({
									delta:1
								})
							},1500)
						});
					}
				})
			}
		}
	}
</script>

<style scoped lang="less">
.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}
.Recharge{
	background-color: #F3F3F3;
	min-height: 100vh;
	overflow: auto;
	// padding-top: 88upx;
	.RechargeBox{
		padding: 16upx 24upx;
		.Rechargemode{
			width: 702upx;
			background: #FFFFFF;
			opacity: 1;
			border-radius: 8upx;
			padding: 32upx 24upx;
			.Rechargetitle{
				font-size: 24upx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #333333;
			}
			.RechargeList{
				margin-top: 32upx;
				.RechargeItem{
					display: flex;
					justify-content: space-between;
					align-items: center;
					margin-bottom: 32upx;
					.item_L{
						display: flex;
						align-items: center;
						.RechargeImage{
							width: 48upx;
							height: 48upx;
							image{
								width: 100%;
								height: 100%;
							}
						}
						.RechargeName{
							font-size: 24upx;
							font-family: Source Han Sans CN;
							font-weight: 400;
							color: #333333;
							margin-left: 16upx;
						}
					}
					.item_R{
						display: flex;
						justify-content: center;
						align-items: center;
						width: 32upx;
						height: 32upx;
						background: #EEEEEE;
						border: 2upx solid #CCCCCC;
						border-radius: 50%;
						opacity: 1;
					}
					.currentColor{
						border: 2upx solid #FFAC3F;
					}
				}
				>.RechargeItem:last-child{
					margin-bottom: 0;
				}
			}
		}
		.amountBox{
			width: 702upx;
			background: #FFFFFF;
			opacity: 1;
			border-radius: 8upx;
			padding: 32upx 24upx;
			margin-top: 16upx;
			.amountTitle{
				font-size: 24upx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				color: #333333;
				margin-bottom: 48upx;
			}
			.inputBox{
				display: flex;
				align-items: flex-end;
				width: 100%;
				font-size: 28upx;
				color: #333333;
				input{
					width: 100%;
					font-size: 40upx;
					color: #333333;
					font-weight: bold;
				}
			}
		}
		.RechargeBtn{
			// position: fixed;
			// bottom: 200upx;
			width: 702upx;
			height: 92upx;
			background: #FFAC3F;
			opacity: 1;
			border-radius: 46upx;
			font-size: 28upx;
			font-family: Source Han Sans CN;
			font-weight: 400;
			line-height: 92upx;
			color: #FFFFFF;
			text-align: center;
			margin-top: 48upx;
		}
	}
}
</style>
